bitkeeper revision 1.1159.154.1 (4189125da-JXVx56I2Sl4SQmQFvGcA)
authormwilli2@equilibrium.research <mwilli2@equilibrium.research>
Wed, 3 Nov 2004 17:16:13 +0000 (17:16 +0000)
committermwilli2@equilibrium.research <mwilli2@equilibrium.research>
Wed, 3 Nov 2004 17:16:13 +0000 (17:16 +0000)
Fix for os.popen problems on some systems.  Not pretty.

.rootkeys
tools/python/xen/sv/Daemon.py
tools/python/xen/util/Brctl.py
tools/python/xen/util/ip.py
tools/python/xen/xend/Blkctl.py
tools/python/xen/xend/server/SrvDaemon.py
tools/python/xen/xend/server/blkif.py
tools/python/xen/xend/util.py [new file with mode: 0644]

index acc4fb6c0dc5416aa91b657d7939e30415aae6f1..4896a7d5e2451c736c61cca3565faa1238a94774 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
 40c9c46925x-Rjb0Cv2f1-l2jZrPYg tools/python/xen/xend/server/netif.py
 40c9c469ZqILEQ8x6yWy0_51jopiCg tools/python/xen/xend/server/params.py
 40c9c469LNxLVizOUpOjEaTKKCm8Aw tools/python/xen/xend/sxp.py
+4189125cL90jKSOcBJ3Vx4nWGiXXvA tools/python/xen/xend/util.py
 40d05079aFRp6NQdo5wIh5Ly31c0cg tools/python/xen/xm/__init__.py
 40cf2937gKQcATgXKGtNeWb1PDH5nA tools/python/xen/xm/create.py
 40f552eariuUSB9TWqCPnDLz5zvxMw tools/python/xen/xm/destroy.py
index 510cfa9f04f8eaa9d993c6ce0a017ee6c6e9a60b..8aeb58720e48fb0cb5fdaf7cbc2d6865e495bbef 100644 (file)
@@ -11,6 +11,7 @@ import sys
 import re
 
 from xen.sv.params import *
+from xen.xend import util
 
 from twisted.internet import reactor
 from twisted.web import static, server, script
@@ -29,7 +30,7 @@ class Daemon:
         cmdex = '(?P<cmd>.*)'
         procre = re.compile('^\s*' + pidex + '\s*' + pythonex + '\s*' + cmdex + '$')
         xendre = re.compile('^/usr/sbin/xend\s*(start|restart)\s*.*$')
-        procs = os.popen('ps -e -o pid,args 2>/dev/null')
+        procs = util.popen('ps -e -o pid,args 2>/dev/null')
         for proc in procs:
             pm = procre.match(proc)
             if not pm: continue
@@ -57,7 +58,7 @@ class Daemon:
             return 0
         # Read the pid of the previous invocation and search active process list.
         pid = open(PID_FILE, 'r').read()
-        lines = os.popen('ps ' + pid + ' 2>/dev/null').readlines()
+        lines = util.popen('ps ' + pid + ' 2>/dev/null').readlines()
         for line in lines:
             if re.search('^ *' + pid + '.+xensv', line):
                 if not kill:
index 7a6f4871dfd25869353dcdf26c98835a65d0adea..569d1b3357f09589ad3f23d857cd2548214c4c5f 100644 (file)
@@ -5,6 +5,8 @@ import os.path
 import re
 import sys
 
+from xen.xend import util
+
 os.defpath = os.defpath + ':/sbin:/usr/sbin:/usr/local/sbin'
 CMD_IFCONFIG = 'ifconfig'
 CMD_ROUTE    = 'route'
@@ -81,7 +83,7 @@ def bridge_del(bridge):
 def routes():
     """Return a list of the routes.
     """
-    fin = os.popen(CMD_ROUTE + ' -n', 'r')
+    fin = util.popen(CMD_ROUTE + ' -n', 'r')
     routes = []
     for x in fin:
         if x.startswith('Kernel'): continue
@@ -102,7 +104,7 @@ def routes():
 def ifconfig(interface):
     """Return the ip config for an interface,
     """
-    fin = os.popen(CMD_IFCONFIG + ' %s' % interface, 'r')
+    fin = util.popen(CMD_IFCONFIG + ' %s' % interface, 'r')
     inetre = re.compile('\s*inet\s*addr:(?P<address>\S*)\s*Bcast:(?P<broadcast>\S*)\s*Mask:(?P<mask>\S*)')
     info = None
     for x in fin:
index 9dd558a178e78c75010b4a06622fa3bdbce52fd9..d130f194211d1db56c8a7344144698d5eaf68c83 100644 (file)
@@ -4,6 +4,8 @@ import socket
 import struct
 import errno
 
+from xen.xend import util
+
 def _readlines(fd):
     """Version of readlines safe against EINTR.
     """
@@ -49,7 +51,7 @@ def get_current_ipaddr(dev='eth0'):
 
     returns interface address as a string
     """
-    fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
+    fd = util.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
     lines = _readlines(fd)
     for line in lines:
         m = re.search( '^\s+inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
@@ -67,7 +69,7 @@ def get_current_ipmask(dev='eth0'):
 
     returns interface netmask as a string
     """
-    fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
+    fd = util.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
     lines = _readlines(fd)
     for line in lines:
         m = re.search( '^.+Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
@@ -85,7 +87,7 @@ def get_current_ipgw(dev='eth0'):
 
     returns gateway address as a string
     """
-    fd = os.popen( '/sbin/route -n' )
+    fd = util.popen( '/sbin/route -n' )
     lines = _readlines(fd)
     for line in lines:
         m = re.search( '^\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' +
index a5bda1947034bd4845952c2427c21c1d71691690..f912a42473104329e8f1f0fd75a170bdaa3ff50a 100644 (file)
@@ -5,6 +5,7 @@ import os.path
 import sys
 import string
 
+from xen.xend import util
 from xen.xend import XendRoot
 xroot = XendRoot.instance()
 
@@ -35,7 +36,7 @@ def block(op, type, dets, script=None):
     script = os.path.join(SCRIPT_DIR, script)
     args = [op] + string.split(dets, ':')
     args = ' '.join(args)
-    out = os.popen(script + ' ' + args)
+    out = util.popen(script + ' ' + args)
 
     output = out.readline()
     out.close()
index cc7da8ee439d0f6d64b630df7f7e0aaee2cf6bca..ea813965ce35a7dcc6cd2d766832cba0e861cab5 100644 (file)
@@ -34,6 +34,7 @@ from xen.xend.XendError import XendError
 from xen.xend.server import SrvServer
 from xen.xend import XendRoot
 from xen.xend.XendLogging import log
+from xen.xend import util
 
 import channel
 import blkif
@@ -336,7 +337,7 @@ class Daemon:
         cmdex = '(?P<cmd>.*)'
         procre = re.compile('^\s*' + pidex + '\s*' + pythonex + '\s*' + cmdex + '$')
         xendre = re.compile('^/usr/sbin/xend\s*(start|restart)\s*.*$')
-        procs = os.popen('ps -e -o pid,args 2>/dev/null')
+        procs = util.popen('ps -e -o pid,args 2>/dev/null')
         for proc in procs:
             pm = procre.match(proc)
             if not pm: continue
@@ -382,7 +383,7 @@ class Daemon:
         """
         running = 0
         if pid:
-            lines = os.popen('ps %d 2>/dev/null' % pid).readlines()
+            lines = util.popen('ps %d 2>/dev/null' % pid).readlines()
             exp = '^ *%d.+%s' % (pid, name)
             for line in lines:
                 if re.search(exp, line):
index 9ca8eab5fe02b51de71dd3f9c46f70ca895c5506..df326134704f9693353706901d4c8e16f1b071d2 100755 (executable)
@@ -8,6 +8,7 @@ from xen.xend import sxp
 from xen.xend import Blkctl
 from xen.xend.XendLogging import log
 from xen.xend.XendError import XendError, VmError
+from xen.xend import util
 
 import os
 import re
@@ -25,7 +26,7 @@ def expand_dev_name(name):
 def check_mounted(self, name):
     mode = None
     name = expand_dev_name(name)
-    lines = os.popen('mount 2>/dev/null').readlines()
+    lines = util.popen('mount 2>/dev/null').readlines()
     exp = re.compile('^' + name + ' .*[\(,]r(?P<mode>[ow])[,\)]')
     for line in lines:
         pm = exp.match(line)
diff --git a/tools/python/xen/xend/util.py b/tools/python/xen/xend/util.py
new file mode 100644 (file)
index 0000000..111d8cd
--- /dev/null
@@ -0,0 +1,36 @@
+# Misc utility functions for Xend
+# (c) 2004 Mark A. Williamson <mark.williamson@cl.cam.ac.uk>
+
+from twisted.internet import utils
+from twisted.internet import reactor
+from XendLogging import log
+from StringIO import StringIO
+
+# This is rather distasteful.  Twisted doesn't play nicely with Python's
+# standard os.popen, so here's an implementation of a synchronous popen that
+# should work reliably. - MAW
+def popen(cmd):
+    global done_flag, result
+
+    done_flag = False
+    result = ''
+    
+    def done(output):
+        global done_flag, result
+        done_flag = True
+        result = output
+
+    def err(output):
+        global done_flag
+# For normal use, suppress debug output here.  It grumbles about stderr if the
+# program exits with $? != 0, even if stderr is redirected.  Grrr!
+#        log.debug("util.popen(\'%s\'): %s" % (cmd, output))
+        done_flag = True
+
+    d = utils.getProcessOutput(cmd)
+    d.addCallbacks(done, err)
+
+    while not done_flag:
+        reactor.iterate()
+
+    return StringIO(result)